<?php


namespace App\Utility;


use EasySwoole\Component\Singleton;
use EasySwoole\Smtp\Exception\Exception;
use EasySwoole\Smtp\Mailer;
use EasySwoole\Smtp\MailerConfig;
use EasySwoole\Smtp\Message\Html;

class Email
{
    use Singleton;

    /**
     * @throws Exception
     */
    public function sendCode($host, $fromMail, $appName, $password, $receive, $content)
    {
        $config = new MailerConfig();
        $config->setServer($host);
        $config->setSsl(true);
        $config->setUsername($fromMail);
        $config->setPassword($password);
        $config->setMailFrom($appName);
        $config->setTimeout(10);//设置客户端连接超时时间
        $config->setMaxPackage(1024*1024*5);//设置包发送的大小：5M

        //设置文本或者html格式
        $mimeBean = new Html();
        $mimeBean->setSubject($content);
        $mimeBean->setBody('<h3>' . $content . '</h3>');
        $mailer = new Mailer($config);
        $mailer->sendTo($receive, $mimeBean);
    }
}